home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions Momentum component
-
- #include "NSDLL.h"
-
- /*****************************/
- /* Gradient search procedure */
-
- __declspec(dllexport) void performMomentum(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *weights, // Pointer to the vector of weights
- int length, // Length of the weight vector
- NSFloat *gradient, // Pointer to the vector of gradients, one for each weight
- NSFloat *step, // Pointer to the learning rate/s
- BOOL individual, // Indicates whether their is one learning rate for all weights (FALSE),
- // or each weight has its own learning rate
- NSFloat momentum, // Momentum rate for all weights
- NSFloat *delta // Last weight Update
- )
- {
- register int i;
-
- for (i=0; i<length; i++)
- weights[i] += delta[i] = momentum*delta[i] + step[individual?i:0]*gradient[i];
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocMomentum(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int length, // Length of the weight vector
- BOOL individual // Indicates whether their is one learning rate for all weights (FALSE),
- // or each weight has its own learning rate
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeMomentum(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */
-
-
- /* Activation of component */
- __declspec(dllexport) BOOL performPrePost(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *input, // Pointer to the input data
- NSFloat *output, // Pointer to the output data
- int rows, // Number of rows of data
- int cols // Number of cols of data
- )
- {
- int i, length=rows*cols;
- for (i=0; i<length; i++)
- output[i] += input[i];
- return TRUE; // Return whether to inject this sample or to call performPrePost with another sample
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocPrePost(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int *rows, // Number of rows of output data, can be changed to reflect a diffenent number for the input data
- int *cols, // Number of cols of output data, can be changed to reflect a diffenent number for the input data
- BOOL preprocessor // Flag to indicate whether this is a preprocessor or postprocessor
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freePrePost(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */